<?php
/**
 * @ClassName: StoreCredential
 * @Description: TODO
 * @author: gydtrade
 * @Date: 2025-10-13 13:14
 * @Version: V1.0.0
 */

namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;

class StoreCredential extends Model
{
    use SoftDelete;

    protected $name = 'store_credential';

    protected $autoWriteTimestamp = 'dateTime';

    public const BUSINESS_LICENSE = 1;
    public const AUTHORIZATION = 2;
    public const FOOD_LICENSE = 3;
    public const PRODUCT_QUALIFICATION = 4;
    public const QUALITY_REPORT = 5;
    public const TRADEMARK = 6;
    public const OTHER = 7;

    public const STATUS_0 = 0;
    public const STATUS_1 = 1;
    public const STATUS_2 = 2;
    public const STATUS_3 = 3;

    public static $certificate_types = [
        self::BUSINESS_LICENSE => '营业执照',
        self::AUTHORIZATION => '授权书',
        self::FOOD_LICENSE => '食品经营许可证',
        self::PRODUCT_QUALIFICATION => '产品资质',
        self::QUALITY_REPORT => '质检报告',
        self::TRADEMARK => '商标',
        self::OTHER => '其他',
    ];

    public static $status_types = [
        self::STATUS_0 => '待审核',
        self::STATUS_1 => '审核通过',
        self::STATUS_2 => '审核拒绝',
        self::STATUS_3 => '已过期',
    ];

    public function getCertificateExpiryStrAttr($value, $data)
    {
        if ($data['certificate_validity_type'] === 1) {
            return '长期有效';
        } else {
            return $data['certificate_expiry'];
        }
    }

    public function store()
    {
        return $this->belongsTo(Store::class, 'store_id', 'id');
    }

}